

function addSensorbitCod(Blockly) {




     //摇杆模块初始化
  Blockly.Python.microbit_rockInit = function(block) {
    var dropdown_rockX = this.getFieldValue('rockX');
    var dropdown_rockY = this.getFieldValue('rockY');
    var dropdown_rockB = this.getFieldValue('rockB');
    Blockly.Python.definitions_['import_microbit'] = 'from microbit import *';
    Blockly.Python.definitions_['import_Rocker'] = 'from input import joystick';
    Blockly.Python.definitions_['rockX'] = 'rockX = '+dropdown_rockX+'';
    Blockly.Python.definitions_['rockY'] = 'rockY = '+dropdown_rockY+'';
    Blockly.Python.definitions_['rockB'] = 'rockB = '+dropdown_rockB+'';
    return '';
  }

    // // 获取摇杆数据数组
    Blockly.Python.microbit_rockData = function(block) {
      Blockly.Python.definitions_['import_microbit'] = 'from microbit import *';
      Blockly.Python.definitions_['import_Rocker'] = 'from input import joystick';
      var dropdown_rockB = this.getFieldValue('rockB');
      Blockly.Python.definitions_['import_rockB' + dropdown_rockB] = 'rockB'+dropdown_rockB+' = '+dropdown_rockB+'';
      var code = "joystick.is_pressed(rockB"+dropdown_rockB+")";
      return [code];
    }
 //  获取摇杆值
  Blockly.Python.microbit_rock = function(block) {
    Blockly.Python.definitions_['import_microbit'] = 'from microbit import *';
    Blockly.Python.definitions_['import_Rocker'] = 'from input import joystick';
    var dropdown_rockX = this.getFieldValue('rockX');
    var dropdown_rockY = this.getFieldValue('rockY');
    Blockly.Python.definitions_['import_rockX' + dropdown_rockX] = 'rockX' + dropdown_rockX + ' = ' + dropdown_rockX + '';
    Blockly.Python.definitions_['import_rockY' + dropdown_rockY] = 'rockY' + dropdown_rockY + ' = ' + dropdown_rockY + '';
    var dropdown_rock = this.getFieldValue('rock2');
    var code = '';
    if("x" == dropdown_rock){
      code = 'joystick.read_x_analog(rockX'+ dropdown_rockX +')';
    }else{
      code = 'joystick.read_y_analog(rockY'+ dropdown_rockY +')';
    }
    return [code];
  }

    return Blockly;
}

module.exports = addSensorbitCod;

